Imports DAL
Imports MyClasses

Public Class BCALC

    Public Shared Function GetDiscount(ByVal DiscOn As Double, ByVal DiscValue As Double, ByVal DiscTypeAorP As Char) As Double
        'FUNCITON CALCULATES THE DISCOUNT ON DiscOn AMOUNT BY DISCVALUE AND RETURNS AS PER DISCTYP
        'IF DISCTYPE IS "A" IT CALCULATES PERCENTAGE & RETURNS IT
        'IF DISCTYPE IS "P" IT CALCULATES AMOUNT & RETURNS IT
        Dim ReturnValue As Double
        Try
            If DiscTypeAorP = "A" Then  'AMOUNT IS PASSED RETURN PERCENTAGE
                ReturnValue = (DiscValue / DiscOn) * 100
            ElseIf DiscTypeAorP = "P" Then 'PERCENTAGE IS PASSED RETURN AMOUNT 
                ReturnValue = (DiscValue * DiscOn) / 100
            Else : ReturnValue = 0
            End If
        Catch ex As Exception
            DGeneral.ErrorHandler(ex.Message, "BAL", "BCALC", "GetDiscount")
            ReturnValue = 0
        Finally
            GetDiscount = Math.Round(ReturnValue, 2)
        End Try
    End Function

    Public Shared Function GetDiscountAmount(ByVal DiscOn As Double, ByVal DiscValue As Double) As Double
        Dim ReturnValue As Double
        Try
            ReturnValue = (DiscValue * DiscOn) / 100
        Catch ex As Exception
            DGeneral.ErrorHandler(ex.Message, "BAL", "BCALC", "GetDiscountAmount")
            ReturnValue = 0
        Finally
            GetDiscountAmount = Math.Round(ReturnValue, 2)
        End Try
    End Function
End Class
